/**
 * Created by PunkVv <punkv@qq.com> on 2016/6/17.
 */

/**
 * 自定义alert
 * @param info
 * @param type 0：error 1:warning 2:info 3:success
 */
function pk_alert(info, type) {
    if (type == 3) {
        toastr.success(info);
    } else if (type == 2) {
        toastr.info(info);
    } else if (type == 1) {
        toastr.warning(info);
    } else {
        toastr.error(info);
    }
}

/**
 * 检查from表单
 * @param obj
 */
function parsley(obj) {
    var errors = obj.find(".validate-has-error:visible");
    if (errors.length > 0) {
        return false;
    }
    return true;
}

/**
 * ajax回调处理
 */
function ajax_call_back(data) {
    if (data.code == 1) {
        pk_alert(data.msg, 3);
        setTimeout(function () {
            if (data.url) {
                location.href = data.url;
            } else {
                location.reload();
            }
        }, data.wait * 1000);
    } else {
        pk_alert(data.msg, 0);
        setTimeout(function () {
            if (data.url) {
                location.href = data.url;
            } else {
                location.reload();
            }
        }, data.wait * 1000);
    }
}